<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use App\Support\Helper;

class AdminAuthPermission
{
    private $_redirectTo = 'admin.login';

    private $_current;

    /**
     * __construct
     */
    public function __construct()
    {
        $this->_current = [
            'method'      => Route::current()->methods,
            'uri'         => Route::current()->uri,
            'name'        => Route::currentRouteName(),
            'request_uri' => $_SERVER['REQUEST_URI']
        ];
    }

    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request 
     * @param \Closure                 $next    
     *
     * @return mixed
     */
    public function handle(\Illuminate\Http\Request $request, Closure $next)
    {
        if (!Auth::check()) {
            return redirect()->route(
                $this->_redirectTo
            );
        }

        return $next($request);
    }
}
